<?php
/**
 * Created by PhpStorm.
 * User: SQK
 * Date: 2018/9/17
 * Time: 14:09
 */
namespace app\mobile\controller;
use cmf\controller\HomeBaseController;
use wechat\Https;
class IndexController extends HomeBaseController{
    /**
     * 会员管理页面
     * @return mixed
     */
    public function index(){
        //获取会员的信息
        //获取会员优惠劵
        return $this->fetch();
    }
    //*********************************微信网页授权*******************************//
    /**
     *
     */
    public function getCode(){
        $appid = 'wx33b50691375205ff';
        $appsecret = 'f8ee806b3d8b13ed2197a833fdfca70d';
        if (!isset($_GET['code'])) {
            $r_uri = 'http://hyxt.w209.madgg.com/mobile/Index/getCode';
            $redirect_uri=urlencode($r_uri);
            $url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$appid.'&redirect_uri='.$redirect_uri.'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect';
            Header("Location: $url");
            exit();
//            $r_url = new Https();
//            $str = $r_url->httpsRequest($url);
        }else{
            $code = $_GET['code'];
            //通过code获取网页授权的access_token
            $url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$appsecret.'&code='.$code.'&grant_type=authorization_code';
            $r_url = new Https();
            $str = $r_url->httpsRequest($url);
            $arr = json_decode($str,1);
            dump($arr);exit;
        }
    }
    /**
     * 一键支付页面
     */
    public function pays(){
       return $this->fetch();
    }
}